package com.wangchao.administrator.zenmechi.ui.registactivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.wangchao.administrator.zenmechi.R;
import com.wangchao.administrator.zenmechi.base.BaseActivity;
import com.wangchao.administrator.zenmechi.ui.loginactivity.LoginActivity;

import butterknife.BindView;

public class RegistActivity extends BaseActivity implements RegistContract.View, View.OnClickListener {

    @BindView(R.id.tv_top_regist)
    TextView tvTopRegist;
    @BindView(R.id.tv_login)
    TextView tvLogin;
    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.et_tel_number)
    EditText etTelNumber;
    @BindView(R.id.tv_yanzheng)
    TextView tvYanzheng;
    @BindView(R.id.et_yanzhengma)
    EditText etYanzhengma;
    @BindView(R.id.bt_OK)
    Button btOK;
    @BindView(R.id.tv_agree)
    TextView tvAgree;
    @BindView(R.id.tv_info)
    TextView tvInfo;
    private RegistPresenter presenter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        presenter = new RegistPresenter(this);
    }

    @Override
    public void initViews() {
        btOK.setOnClickListener(this);
        tvLogin.setOnClickListener(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_regist;
    }

    @Override
    public void registSuccess(String id) {
        Toast.makeText(this,"注册成功 用户ID为："+id,Toast.LENGTH_SHORT).show();
        goActivity();
    }
    public void goActivity(){
        Intent loginIntent=new Intent(this, LoginActivity.class);
        startActivity(loginIntent);
    }

    @Override
    public void registFailed(String msg) {
        Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_OK:
                String name = etTelNumber.getText().toString().trim();
                String pwd = etYanzhengma.getText().toString().trim();
                if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(pwd)) {
                    presenter.getData(name,pwd);
                }else{
                    Toast.makeText(this,"用户名/密码不能为空",Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.tv_login:
                goActivity();
                break;
        }
    }
}
